import SwiftUI
import SPGlassKit

public struct GlassSegmentedControlExample: GlassExample {
    public static let componentID = "glass-segmented-control"

    enum Mode: String, CaseIterable, Hashable {
        case list, grid, map

        var title: String { rawValue.capitalized }
    }

    @State private var mode = Mode.list
    @State private var period = "Week"
    @State private var long = "Everything that happened"
    @State private var weekday = "Mon"

    public init() {}

    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 24) {
                GlassSegmentedControl("View", selection: $mode, options: Mode.allCases, title: \.title)
                Text("Showing: \(mode.title)").font(.callout).foregroundStyle(.secondary)

                GlassSegmentedControl("Period", selection: $period, options: ["Day", "Week", "Month", "Year"]) { $0 }

                Text("Titles too long for the width fall back to a menu").font(.headline)
                GlassSegmentedControl("Scope", selection: $long, options: ["Everything that happened", "Only what I was mentioned in", "Nothing at all, thank you"]) { $0 }

                Text("More than five options: a menu").font(.headline)
                GlassSegmentedControl("Day", selection: $weekday, options: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) { $0 }

                GlassSegmentedControl("Locked", selection: .constant("On"), options: ["Off", "On"]) { $0 }
                    .disabled(true)
            }
            .frame(maxWidth: .infinity, alignment: .leading)
            .padding()
        }
    }
}

#Preview("GlassSegmentedControl") { GlassSegmentedControlExample() }
